package controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.DevUser;
import service.AppInfoService;
import service.DevUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@Controller
public class DevUserController {
     @Resource
    private DevUserService devUserService;
    @Resource
    private AppInfoService appInfoService;

    @RequestMapping( "/index")
    public String index(){
        return "login";
    }


    //注销;

    @RequestMapping( "/cancel")
    public String cancel(String  loginObject,HttpSession sessioon){
        sessioon.removeAttribute(loginObject);
        sessioon.invalidate();
        return "login";
    }

    //登陆
    @RequestMapping( "/login")
    public String login(String devCode, String devPassword, HttpSession sessioon, Model model ){
        DevUser devUser=null;
       // BackendUser backendUser=new BackendUser();
        devUser=devUserService.LoginDevUser(devCode,devPassword);
        if(devUser!=null){
            sessioon.setAttribute("devUser",devUser);
            sessioon.setAttribute("status",appInfoService.DataDictionaryList("APP_STATUS"));
            sessioon.setAttribute("appCategorylist",appInfoService.appCategoryList(null));
            sessioon.setAttribute("flatforms",appInfoService.DataDictionaryList("APP_FLATFORM"));
         //   sessioon.setAttribute("backendUser",backendUser);
             // appInfoService.appCategoryList(null);
            return "index";
        }
        model.addAttribute("devCode",devCode);
        model.addAttribute("devPassword",devPassword);
        return "login";
    }

}
